home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / SMTPCEMS.ZIP / MAILER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-15  |  3.3 KB  |  112 lines

  1. /*
  2. **  MAILER.C [edit EMAIL.H before compiling]
  3. **
  4. **  This program emails a specified message.
  5. */
  6.  
  7. #define USE_SEE_DRIVER 1
  8.  
  9. #include <windows.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "see.h"
  13. #include "email.h"
  14.  
  15. #define QUOTE 0x22
  16.  
  17. static char Buffer[512];
  18.  
  19. /* display error message */
  20.  
  21. static void ErrorExit(int Code, LPSTR Msg)
  22. {printf("ERROR: ");
  23.  if(Msg) printf("%s\n",Msg);
  24.  if(Code)
  25.    {seeErrorText(Code,(LPSTR)Buffer,50);
  26.     printf("%s\n",(LPSTR)Buffer);
  27.     exit(1);
  28.    }
  29. }
  30.  
  31. void main(int argc, char *argv[])
  32. {int Code; 
  33.  int Version;
  34.  LPSTR Attach = NULL;
  35.  ULONG TimeMark;
  36.  long BytesSent;
  37.  if((argc!=4)&&(argc!=5))
  38.    {printf("Usage: MAILER email-text subject <email-addr>\n");
  39.     printf("Usage: MAILER email-text subject <email-addr> {attach-file}\n");
  40.     printf("   eg: MAILER %c@test.mai%c %cThis is a test%c %c<mike@marshallsoft.com>%c\n",
  41.                    QUOTE,QUOTE,QUOTE,QUOTE,QUOTE,QUOTE);
  42.     exit(1);
  43.    } 
  44.  
  45.  /* display parameters */
  46.   
  47.  Version = seeStatistics(SEE_GET_VERSION);
  48.  printf("SEE4C Version %1x.%1x.%1x\n",0x0f&(Version>>8),0x0f&(Version>>4),0x0f&Version);
  49.  printf("Server : %s\n",(LPSTR)SMTP_HOST_NAME);
  50.  printf("  From : %s\n",(LPSTR)YOUR_EMAIL_ADDR);
  51.  if(*argv[1]=='@') printf("  File : %s\n", argv[1]);
  52.  else printf("  Text : %c%s%c\n", QUOTE,argv[1],QUOTE);
  53.  printf("  Subj : %s\n", argv[2]);
  54.  printf("    To : %s\n", argv[3]);
  55.  if(argc>4) 
  56.    {Attach = argv[4];
  57.     printf(" Attach: %s\n", Attach);
  58.    }
  59.  /* check format of email addresses */
  60.  Code = seeVerifyFormat((LPSTR)argv[3]);
  61.  if(Code<0) ErrorExit(Code,(LPSTR)argv[3]);
  62.  Code = seeVerifyFormat(YOUR_EMAIL_ADDR);
  63.  if(Code<0) ErrorExit(Code,(LPSTR)YOUR_EMAIL_ADDR);
  64.  
  65.  /* define diagnostics log file */
  66.  seeStringParam(SEE_LOG_FILE, (LPSTR)"mailer.log"); 
  67.  
  68.  /* connect to SMTP server */
  69.  printf("Connecting to SMTP server %s\n", SMTP_HOST_NAME);
  70.  Code = seeSmtpConnect(
  71.     (LPSTR)SMTP_HOST_NAME,           /* SMTP server */
  72.     (LPSTR)YOUR_EMAIL_ADDR,          /* return email address */ 
  73.     (LPSTR)NULL);                    /* Reply-To header */
  74.  if(Code<0)ErrorExit(Code,(LPSTR)"Connect:"); 
  75.  
  76.  /* turn off AUTO CALL driver */
  77.  if(USE_SEE_DRIVER) seeIntegerParam(SEE_AUTO_CALL_DRIVER, 0);
  78.  
  79.  /* send email */
  80.  Code = seeSendEmail(
  81.     (LPSTR)argv[3],                  /* To list */
  82.     (LPSTR)NULL,                     /* CC list */
  83.     (LPSTR)NULL,                     /* BCC list */
  84.     (LPSTR)argv[2],                  /* subject */
  85.     (LPSTR)argv[1],                  /* message text */
  86.     Attach);                         /* MIME attachment */                
  87.  if(Code<0) ErrorExit(Code,(LPSTR)"Sending email:"); 
  88.  
  89.  if(USE_SEE_DRIVER)
  90.    {puts("Sending mail...");
  91.     /* run the driver to send the email */
  92.     TimeMark = GetCurrentTime() + 500; /* WIN32 API function */
  93.     while(1)
  94.       {Code = seeDriver();
  95.        if((GetCurrentTime()>=TimeMark)||(Code==0))
  96.          {TimeMark = GetCurrentTime() + 500;
  97.           /* display progress */
  98.           BytesSent = (long) seeStatistics(SEE_GET_TOTAL_BYTES_SENT);
  99.           printf("%ld bytes written.\r",BytesSent);
  100.          }
  101.        if(Code==0) break;
  102.       }
  103.     printf("\n");
  104.     /* turn AUTO CALL back on for seeClose */
  105.     seeIntegerParam(SEE_AUTO_CALL_DRIVER, 1);
  106.    } 
  107.  
  108.  seeClose();
  109. } /* end main */
  110.  
  111.  
  112.